package com.thor.palmmall.rest.process.converter;

import java.util.ArrayList;
import java.util.List;

import org.springframework.core.convert.converter.Converter;

import com.thor.palmmall.rest.process.AProcessAttentions;
import com.thor.palmmall.rest.todo.ATaskQueryCount;
import com.thor.palmmall.spi.process.SProcessAttentions;
import com.thor.palmmall.spi.todo.STaskQueryCount;

public class AProcessAttentionsConverter implements Converter<SProcessAttentions,AProcessAttentions>{
  public static AProcessAttentionsConverter getInstance() {
    if (instance == null)
      instance = new AProcessAttentionsConverter();
    return instance;
  }

  private static AProcessAttentionsConverter instance;

  private AProcessAttentionsConverter() {
  }

  @Override
  public AProcessAttentions convert(SProcessAttentions source) {
    if (source == null){
      return null;
    }
    AProcessAttentions target = new AProcessAttentions();
    List<ATaskQueryCount> processes = new ArrayList<ATaskQueryCount>();
    List<STaskQueryCount> counts = source.getCounts(); 
    for (STaskQueryCount sTaskQueryCount : counts) {
      ATaskQueryCount a = new ATaskQueryCount();
      a.setCount(sTaskQueryCount.getCount());
      a.setDefinitionKey(sTaskQueryCount.getDefinitionKey());
      a.setDefinitionName(sTaskQueryCount.getDefinitionName());
      processes.add(a);
    }
    target.setCounts(processes);
    return target;
    
  }
}
